//
//  StockTableController.m
//  iStock Global
//
//  Created by Andy on 2010/10/1.
//  Copyright 2010 __MyCompanyName__. All rights reserved.
//

#import "StockTableController.h"
#import "DBHelper.h"
#import "addWatchList.h"
#import "StockTableQuote.h"
#import "AppDelegate.h"
#import "MoveArray.h"



@implementation StockTableController

@synthesize AppleDeglate;
#pragma mark -
#pragma mark 重新更新自選股內容
-(void)refreshWatchList{
	NSLog(@"refresh watch list");
	[self datasql];	
}

#pragma mark -
#pragma mark 表格編輯與新增自選股群組
//刪除用
-(void)tableView:(UITableView *)tableView commitEditingStyle:(UITableViewCellEditingStyle)editingStyle forRowAtIndexPath:(NSIndexPath *)indexPath{
	 NSLog(@"儲存投資組合名冊");    
    if (editingStyle==UITableViewCellEditingStyleDelete) {
	 	if (indexPath.row >0 ) {
			
			[classd removeObjectAtIndex:indexPath.row];
			[tableView deleteRowsAtIndexPaths: [NSArray arrayWithObject:indexPath] withRowAnimation:UITableViewRowAnimationFade];
			
			if ([classd count]==1) {
				[classd addObject:@"Sample 1"];
				 
			}
			
			
			//儲存自選股
            NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
			NSString *dir = [paths objectAtIndex:0];
			NSString *filePathw;
			filePathw = [[NSString alloc] initWithString:[dir stringByAppendingPathComponent:@"WatchListClass.cplist"]];
			NSMutableArray *tempclassd;
			tempclassd=[[NSMutableArray alloc] init];
			for (int i=1; i<[classd count]; i++) {
				[tempclassd addObject:[classd objectAtIndex:i]];
			}
			
			[tempclassd writeToFile:filePathw atomically:NO];	
            [filePathw release];
			
            //重新載入資料
			[self datasql];	
			[tempclassd release];
            [myTable reloadData];
			
		}
		else {
			UIAlertView *ai;
			ai=[[UIAlertView alloc ] initWithTitle:NSLocalizedString(@"WATCHLIST",@"WATCHLIST") message:@"Can not Delete" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
			[ai show];
            [ai release];
		}

		
	}
	
}

//新增 輸入表單
-(void)addWatchList{
	NSLog(@"addWatchList");
    
    
    if ( WillSaveFirstWatchlist==YES) {
        //此段程式主要是因為新規定僅有使用者產生的文件才可以放在document 特別額外寫的程式
        WillSaveFirstWatchlist=NO;
        [self first_save_watchlist];
        
    }
    
    
    
    addWatchList *oaddwatchlist;
	oaddwatchlist=[[addWatchList alloc] init];
    oaddwatchlist.delegate=self;
	oaddwatchlist.AppleDeglate=AppleDeglate;
    
    
     if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad){
         
         if ( [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString:@"UIInterfaceOrientationPortrait 垂直"] || [[(AppDelegate * )AppleDeglate interfaceOrientation_ipad] isEqualToString: @"UIInterfaceOrientationPortraitUpsideDown 垂直"] ) {
             //垂直
             //主圖消失
             [[(AppDelegate * )AppleDeglate Master_popController] dismissPopoverAnimated:YES];         
             //顯示增加群組視窗
             oaddwatchlist.modalPresentationStyle=UIModalPresentationFormSheet;
             [self presentModalViewController:oaddwatchlist animated:YES];             
             
                    
         }
         else{
             //水平
             
             
             /* 重要錯誤
             UIPopoverController* popController = [[[UIPopoverController alloc] initWithContentViewController:oaddwatchlist] autorelease];
             
             oaddwatchlist.delegate_UIPopoverController=popController;
             
             popController.popoverContentSize = CGSizeMake(320,480);
             
             [popController presentPopoverFromBarButtonItem: plusButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];  
             */
             //主圖消失
             [[(AppDelegate * )AppleDeglate Master_popController] dismissPopoverAnimated:YES];
             //顯示增加群組視窗
             oaddwatchlist.modalPresentationStyle=UIModalPresentationFormSheet;
             [self presentModalViewController:oaddwatchlist animated:YES];
             
                  
         }
         
                 
         
     }
     else{
         oaddwatchlist.modalTransitionStyle =UIModalTransitionStyleCoverVertical;  
         [self presentModalViewController:oaddwatchlist animated:YES];     
     }
    
	
	[oaddwatchlist release];	
}

#pragma mark -
#pragma mark 第一次儲存自選股
-(void)first_save_watchlist{

    
     //儲存自選股群組
     [self SaveGroupName];
     
     //儲存自選股明細
     NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
     NSString *dir = [paths objectAtIndex:0];
     NSString *filePathw;
     filePathw = [[NSString alloc] initWithString:[dir stringByAppendingPathComponent:[NSString stringWithFormat: @"WatchList_%@.cplist",NSLocalizedString(@"Sample1",@"Sample1")]]];
     NSMutableArray *awr;
     awr=[[NSMutableArray alloc] init];
     for (int i=0; i<[code_array count]; i++) {
     NSString *wr;
     wr=[NSString stringWithFormat:@"%@_%@_%@_34.5_56000",[code_array objectAtIndex:i],[name_array objectAtIndex:i], [id_class_array objectAtIndex:i]];
     [awr addObject:wr];
     }
     
     [awr writeToFile:filePathw atomically:NO];					
     [filePathw release];
     [awr release];
     
}


//新增 委託事件
#pragma mark -
#pragma mark 完成增加自選股群組
-(void)viewWillAppear:(BOOL)animated{
     NSLog(@"viewWillAppear=%@",self.title)  ;  
	[self datasql];	
	
    [myTable reloadData];
    

}


- (void)addWatchListControllerDidFinish:(addWatchList *)controller{
	[self dismissModalViewControllerAnimated:YES];	
	
	if ([[[controller addw] text] isEqualToString:@""] ) {
		
		
		return;
	 }
	
	[classd addObject:   [[controller addw] text]   ];
	 

	 [myTable reloadData];	
	
	//儲存自選股群組名稱
	[self SaveGroupName];
	
	//重新載入資料
	[self datasql];
}
//儲存自選股群組名稱
-(void)SaveGroupName{
   
    
    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
	NSString *dir = [paths objectAtIndex:0];
	NSString *filePathw;
	filePathw = [[NSString alloc] initWithString:[dir stringByAppendingPathComponent:@"WatchListClass.cplist"]];
	NSMutableArray *tempclassd;
	tempclassd=[[NSMutableArray alloc] init];
	for (int i=1; i<[classd count]; i++) {
		[tempclassd addObject:[classd objectAtIndex:i]];
	}
	[tempclassd writeToFile:filePathw atomically:NO];	
	[tempclassd release];
    [filePathw release];
}


#pragma mark -
#pragma mark 初始化

// The designated initializer.  Override if you create the controller programmatically and want to perform customization that is not appropriate for viewDidLoad.
//內定初始化
-(id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
    if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
        
		
		myTable = [[UITableView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame style:UITableViewStylePlain];
	 
        //標記:判斷是MESA或LF
        NSString *DisplayName;
        DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
        NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];        
        if ([DisplayName_array count]>=3) {
            if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
                //MESA
                myTable.backgroundColor=[UIColor blackColor];             
            }
            else{
                //開始LF
                
                
                
            }
        }
        
        
        
        
        
		myTable.dataSource = self;	
		myTable.delegate=self;
		
		 
	 
		
    }
    return self;
}
-(id)initWithStyle:(UITableViewStyle)style{
	self= [super initWithStyle:style];
    if (self) {
		self.navigationItem.backBarButtonItem.title=@"gobackf";
	} 
	return self;
}// Implement loadView to create a view hierarchy programmatically, without using a nib.
-(void)loadView {
 	
    WillSaveFirstWatchlist=NO;
	self.view=myTable;
	//[self datasql];
	
	
}
//自設初始化
-(void)get_navcontroller:(navcontroller *)nd{
	navdelegete=nd;
}
-(void)initTitle:(NSString *)bartitle{
	self.title=bartitle;
	almarket=bartitle;
	
	//如果是自選股
	if ([bartitle isEqualToString:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")]) {	
	 plusButton = [[UIBarButtonItem alloc]             
								   initWithBarButtonSystemItem:UIBarButtonSystemItemAdd target:self
								   action:@selector(addWatchList)]; 
	
	
        
      /* 
    UIBarButtonItem * editItem;
    editItem = [[UIBarButtonItem alloc] initWithTitle:@"New Name" style:UIBarButtonItemStyleBordered target:self action:@selector(addWatchList)];
        */
        
    self.navigationItem.leftBarButtonItem =  self.editButtonItem;  
    self.navigationItem.rightBarButtonItem = plusButton;	
		
	 
		 
	}
	
	
}
-(void)initImage:(UIImage*)image{
	self.tabBarItem.image= image ;
}

//Table 行與格資料設定
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
	return [classd count];
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
	 	
	static NSString *CellIdentifier = @"Cell";
    
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
    }
    
	cell.textLabel.text=[classd objectAtIndex:indexPath.row];
   
    
    //標記:判斷是MESA或LF
    NSString *DisplayName;
    DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"];     
    NSArray * DisplayName_array=[ DisplayName componentsSeparatedByString:@"_"];        
    if ([DisplayName_array count]>=3) {
        if ([[DisplayName_array objectAtIndex:2] isEqualToString:@"MESA"] ) {
            //MESA
            //標記:Bloomberg 橘色        
            cell.textLabel.textColor =[UIColor colorWithRed:225.0/255.0 green:120.0/255.0 blue:20.0/255.0 alpha:1.0];
            cell.accessoryType=UITableViewCellAccessoryDisclosureIndicator;    
            
            
                    
        }
        else{
            //開始LF
                        
            
            
        }
    }
  
    return cell;	
	
	
	
}


//Table 表格行選定
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath {
 
    if ( WillSaveFirstWatchlist==YES) {
        //此段程式主要是因為新規定僅有使用者產生的文件才可以放在document 特別額外寫的程式
        WillSaveFirstWatchlist=NO;
        [self first_save_watchlist];
    
    }
    
	
	NSString *selname;
	selname=[classd objectAtIndex:indexPath.row];
	// 決定次目錄名稱
    {
        StockTableQuote *stocktable;   
		stocktable=[[StockTableQuote alloc] initWithNibName:nil bundle:nil ];
		//[stocktable autorelease];
		stocktable.title=selname;
		stocktable.market=self.title;
		stocktable.data_code=[code_sarray objectAtIndex:indexPath.row];
		stocktable.data_name=[name_sarray objectAtIndex:indexPath.row];
		stocktable.data_class=[class_sarray objectAtIndex:indexPath.row];
		stocktable.data_id_class=[id_class_sarray objectAtIndex:indexPath.row];		
		stocktable.delgete=self;
		
        stocktable.AppleDeglate=AppleDeglate;
        
        [stocktable get_navcontroller:navdelegete];
		
		[navdelegete pushViewController:stocktable animated:YES];			
		
		 [stocktable release];
	
	}
		
		 		
	 
	
	
	
	
	
}
 
#pragma mark -
#pragma mark  表格排序專用 
//要將兩個tableView:的委託事件同時放上去才會出現排序選項 canMoveRowAtIndexPath moveRowAtIndexPath

- (BOOL)tableView:(UITableView *)tableView canMoveRowAtIndexPath:(NSIndexPath *)indexPath{
	if (indexPath.row==0) {
        return NO; //限制全部市場不可以排列順序
    }
    else{
        return YES;    
    }
        
   
}
- (void)tableView:(UITableView *)tableView moveRowAtIndexPath:(NSIndexPath *)fromIndexPath
	  toIndexPath:(NSIndexPath *)toIndexPath{
   
    
    
    if (toIndexPath.row==0) {
       //如果要動到第一個商品則回到原位
        [myTable reloadData];
        
    }
    else{
        
        //標記:NSMutableArray 的內存物件可以互相調換位置
        [classd moveObjectFromIndex:fromIndexPath.row toIndex:toIndexPath.row]; 
        [code_sarray moveObjectFromIndex:fromIndexPath.row toIndex:toIndexPath.row]; 
        [name_sarray moveObjectFromIndex:fromIndexPath.row toIndex:toIndexPath.row]; 
        [class_sarray moveObjectFromIndex:fromIndexPath.row toIndex:toIndexPath.row]; 
        [id_class_sarray moveObjectFromIndex:fromIndexPath.row toIndex:toIndexPath.row];    
        
        
        //儲存自選股
        NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
        NSString *dir = [paths objectAtIndex:0];
        NSString *filePathw;
        filePathw = [[NSString alloc] initWithString:[dir stringByAppendingPathComponent:@"WatchListClass.cplist"]];
        NSMutableArray *tempclassd;
        tempclassd=[[NSMutableArray alloc] init];
        for (int i=1; i<[classd count]; i++) {
            [tempclassd addObject:[classd objectAtIndex:i]];
        }
        
        [tempclassd writeToFile:filePathw atomically:NO];	
        
        [filePathw release];    
        [tempclassd release];
    
    
    
    }
        
}
 




#pragma mark -
#pragma mark 記憶體最佳化處理

-(void)viewWillDisappear:(BOOL)animated{
    
     NSLog(@"viewWillDisappear=%@",self.title)  ; 
    //[self Realese_Menory];
}
-(void)Realese_Menory{
    NSLog(@"ReleaseMenory=%@",self.title);
    NSMutableArray *code_pre;
    NSMutableArray *name_pre;
    NSMutableArray *class_pre;
    NSMutableArray *id_class_pre;
    NSMutableArray *classd_pre;        
    
    code_pre=code_array;
    name_pre=name_array;
    class_pre=class_array;
    id_class_pre=id_class_array;
    classd_pre=classd;        
    
    
    //標記:記憶體釋放技巧 4.NSMutableArray 只要release 就會對所有下層加入的物件也各別release ㄧ次
    
    if (code_pre!=nil) {
        [code_pre release];
    }
    if (name_pre!=nil) {
        [name_pre release];
    }        
    if (class_pre!=nil) {
        [class_pre release];
    }
    if (id_class_pre!=nil) {
        [id_class_pre release];
    }        
    if ( classd_pre!=nil) {
        [ classd_pre release];
    }          
    
    
    NSMutableArray *code_sarray_pre;
    NSMutableArray *name_sarray_pre; 
    NSMutableArray *class_sarray_pre;
    NSMutableArray *id_class_sarray_pre;        
    NSMutableArray *sectionArray_pre; 
    
    code_sarray_pre=  code_sarray;  
    name_sarray_pre=name_sarray;
    class_sarray_pre=  class_sarray;  
    id_class_sarray_pre=id_class_sarray;        
    sectionArray_pre=sectionArray;        
     	
    
    if (code_sarray_pre ) {
        [code_sarray_pre release];
    }
    if ( name_sarray_pre ) {
        [ name_sarray_pre release];
    }
    if ( class_sarray_pre ) {
        [ class_sarray_pre release];
    }
    if ( id_class_sarray_pre ) {
        [id_class_sarray_pre release];
    }
    if (sectionArray_pre ) {
        [sectionArray_pre release];
    }            
         
    
    
    
    
    
}


#pragma mark -
#pragma mark 資料庫初使化

-(void)datasql{
	
    if ([self.title isEqualToString:NSLocalizedString(@"WATCHLIST",@"WATCHLIST")] ){
		NSLog(@"WATCHLIST_start");
		
        		code_array=	[[NSMutableArray alloc] init];
		name_array=	[[NSMutableArray alloc] init];
        class_array=[[NSMutableArray alloc] init];
		id_class_array=[[NSMutableArray alloc] init];		
        classd=[[NSMutableArray alloc] init];	
       
        
        
        
		
	    [classd addObject:NSLocalizedString(@"全部自選股",@"全部自選股")];
		//從檔案取出自選股資料
		//檔案路徑
		NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
		NSString *dir = [paths objectAtIndex:0];
		NSString *filePathw;
		filePathw = [[NSString alloc] initWithString:[dir stringByAppendingPathComponent:@"WatchListClass.cplist"]];
		NSMutableArray *watchc;
		NSFileManager *fileManager = [NSFileManager defaultManager];
       // [filePathw release];
		if ([fileManager fileExistsAtPath:filePathw] == NO){
			//如果沒有檔案資料 則是範例自設的初始化
            [filePathw release];
		 	[classd addObject:NSLocalizedString(@"Sample1",@"Sample1")];
			
            
            NSString *DisplayName;
            DisplayName=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleDisplayName"]; 
           
            //標記:Add Target need Program            
            if ([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_ETF"]) {
                /*
                [code_array addObject:@"QQQQ"];
                [name_array addObject:@"PowerShares QQQ"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"US Major Markets ETFs" ];			
                 */
                
                
                [code_array addObject:@"ADRD"];
                [name_array addObject:@"BLDRS Developed Markets 100"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Broad International ETFs" ];
                
                
                [code_array addObject:@"GLD"];
                [name_array addObject:@"SPDR Gold Trust"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Commodity ETFs" ];			
               
                
                
                [code_array addObject:@"DXD"];
                [name_array addObject:@"ProShares UltraShort Dow 30"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Leveraged,Inverse" ];
             
                
                     
                
                
            } 
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_iStock Global"]  ){
                    
                
                [code_array addObject:@"AAPL"];
                [name_array addObject:@"APPLE INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Computers & Peripherals" ];			
              
                
                
                [code_array addObject:@"INTU"];
                [name_array addObject:@"INTUIT INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Software" ];
               
                
                
                [code_array addObject:@"0001.HK"];
                [name_array addObject:@"長江實業"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"地產" ];			
                               
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_HK"]  ) {
            
                        
            [code_array addObject:@"0001.HK"];
            [name_array addObject:@"長江實業"];
            [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
            [id_class_array addObject: @"地產" ];			
            
            
                
            [code_array addObject:@"0700.HK"];
            [name_array addObject:@"騰訊"];
            [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
            [id_class_array addObject: @"資訊科技業" ];   
                
                
            [code_array addObject:@"0013.HK"];
            [name_array addObject:@"和記黃埔"];
            [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
            [id_class_array addObject: @"綜合企業" ];    
                
                
        }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CH"]  ) {
                
                
                [code_array addObject:@"600111.SS"];
                [name_array addObject:@"包钢稀土"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"制造业" ];			
                
                
                
                [code_array addObject:@"600585.SS"];
                [name_array addObject:@"海螺水泥"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"制造业" ];   
                
                
                [code_array addObject:@"600058.SS"];
                [name_array addObject:@"五矿发展"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"批发和零售贸易" ];    
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_US"]  ) {
                
                [code_array addObject:@"AAPL"];
                [name_array addObject:@"APPLE INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Computers & Peripherals" ];			
                
                
                
                [code_array addObject:@"INTU"];
                [name_array addObject:@"INTUIT INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Software" ];                     
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_UK"]  ) {
                
                [code_array addObject:@"HSBA.L"];
                [name_array addObject:@"HSBC HLDGS PLC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Banks" ];			
                
                
                
                [code_array addObject:@"VOD.L"];
                [name_array addObject:@"VODAFONE GROUP"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Wireless Telecommunciation Service" ];                     
                
                
                [code_array addObject:@"RIO.L"];
                [name_array addObject:@"RIO TINTO PLC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Diversified Metals & Mining" ];                  
                
            }
			else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_CN"]  ) {
                
                [code_array addObject:@"AEM.TO"];
                [name_array addObject:@"AGNICO-EAGLE MIN"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Gld" ];			
                
                
                
                [code_array addObject:@"CM.TO"];
                [name_array addObject:@"CAN IMPL BK COMN"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Diversified Banks" ];                     
                
                
                [code_array addObject:@"CNR.TO"];
                [name_array addObject:@"CAN NATL RAILWAY"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Railroads" ];                  
                
                [code_array addObject:@"HSE.TO"];
                [name_array addObject:@"HUSKY ENERGY INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Intergrated Oil&Gas" ];                  
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_KS"]  ) {
                
                [code_array addObject:@"005930.KS"];
                [name_array addObject:@"삼성전자"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Semiconductors &amp" ];			
                
                
                
                [code_array addObject:@"005380.KS"];
                [name_array addObject:@"현대자동차"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Automobiles" ];                     
                
                
                [code_array addObject:@"005490.KS"];
                [name_array addObject:@"포스코"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Metals &amp" ];                  
                
                [code_array addObject:@"009540.KS"];
                [name_array addObject:@"현대중공업"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Machinery" ];                  
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_iStock Global"]  ){
                
                
                [code_array addObject:@"AAPL"];
                [name_array addObject:@"APPLE INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Computers & Peripherals" ];			
                
                
                
                [code_array addObject:@"INTU"];
                [name_array addObject:@"INTUIT INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Software" ];
                
                
                
                [code_array addObject:@"0001.HK"];
                [name_array addObject:@"長江實業"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"地產" ];			
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_HK"]  ) {
                
                
                [code_array addObject:@"0001.HK"];
                [name_array addObject:@"長江實業"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"地產" ];			
                
                
                
                [code_array addObject:@"0700.HK"];
                [name_array addObject:@"騰訊"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"資訊科技業" ];   
                
                
                [code_array addObject:@"0013.HK"];
                [name_array addObject:@"和記黃埔"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"綜合企業" ];    
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SI"]  ) {
                
                
                [code_array addObject:@"E5H.SI"];
                [name_array addObject:@"GoldenAgr"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Agriculture" ];			
                
                
                
                [code_array addObject:@"O32.SI"];
                [name_array addObject:@"Olam"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Commerce" ];   
                
                
                [code_array addObject:@"C31.SI"];
                [name_array addObject:@"Capitaland"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Properties" ]; 
                
                [code_array addObject:@"C38U.SI"];
                [name_array addObject:@"CapitaMall"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Properties" ];
                
                                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CH"]  ) {
                
                [code_array addObject:@"600111.SS"];
                [name_array addObject:@"包钢稀土"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"制造业" ];			
                
                
                
                [code_array addObject:@"600585.SS"];
                [name_array addObject:@"海螺水泥"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"制造业" ];   
                
                
                [code_array addObject:@"600058.SS"];
                [name_array addObject:@"五矿发展"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"批发和零售贸易" ];    
                
                   
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_AX"]  ) {
             
                
                
                [code_array addObject:@"LYC.AX"];
                [name_array addObject:@"LYNAS CORP LTD"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Metals &amp; Mining" ];			
                
                
                
                [code_array addObject:@"SDL.AX"];
                [name_array addObject:@"SUNDANCE RESOURC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Steel" ];   
                
                
                [code_array addObject:@"TLS.AX"];
                [name_array addObject:@"TELSTRA CORP"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Integrated Telecommunication Services" ]; 
                
                [code_array addObject:@"GNS.AX"];
                [name_array addObject:@"GUNNS LTD"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Forest Products" ];
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_GR"]  ) {
                        
                
                
                [code_array addObject:@"BMW.DE"];
                [name_array addObject:@"BAYER MOTOREN WK"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Automobile Manufacturers" ];			
                
                
                
                [code_array addObject:@"BAYN.DE"];
                [name_array addObject:@"BAYER AG-REG"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Pharmaceuticals" ];   
                
                
                [code_array addObject:@"SIE.DE"];
                [name_array addObject:@"SIEMENS AG-REG"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Industrial Conglomerates" ]; 
                
                [code_array addObject:@"TKA.DE"];
                [name_array addObject:@"THYSSENKRUPP AG"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Steel" ];
                
                
                [code_array addObject:@"CBK.DE"];
                [name_array addObject:@"COMMERZBANK"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Banks" ];                
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_PA"]  ) {
                /*
                <string>___34.5_56000</string>
                <string>___34.5_56000</string>
                <string>___34.5_56000</string>
                <string>___34.5_56000</string>
                <string>___34.5_56000</string>                
                */
                
                [code_array addObject:@"MC.PA"];
                [name_array addObject:@"LVMH MOET HENNES"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Apparel, Accessories &amp; Luxury Goods" ];			
                
                [code_array addObject:@"ACA.PA"];
                [name_array addObject:@"CREDIT AGRICOLE"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Banks" ];   
                
                
                [code_array addObject:@"BN.PA"];
                [name_array addObject:@"DANONE"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Packaged Foods &amp; Meats" ]; 
                
                [code_array addObject:@"PP.PA"];
                [name_array addObject:@"PPR"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Department Stores" ];
                
                [code_array addObject:@"VIV.PA"];
                [name_array addObject:@"VIVENDI"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Movies &amp; Entertainment" ];
                
                
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_CN"]  ) {
                
                [code_array addObject:@"AEM.TO"];
                [name_array addObject:@"AGNICO-EAGLE MIN"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Gld" ];			
                
                
                
                [code_array addObject:@"CM.TO"];
                [name_array addObject:@"CAN IMPL BK COMN"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Diversified Banks" ];                     
                
                
                [code_array addObject:@"CNR.TO"];
                [name_array addObject:@"CAN NATL RAILWAY"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Railroads" ];                  
                
                [code_array addObject:@"HSE.TO"];
                [name_array addObject:@"HUSKY ENERGY INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Intergrated Oil&Gas" ];                  
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_PA"]  ) {
                                
                [code_array addObject:@"MC.PA"];
                [name_array addObject:@"LVMH MOET HENNES"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Apparel, Accessories &amp; Luxury Goods" ];			
                
                [code_array addObject:@"ACA.PA"];
                [name_array addObject:@"CREDIT AGRICOLE"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Banks" ];   
                
                
                [code_array addObject:@"BN.PA"];
                [name_array addObject:@"DANONE"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Packaged Foods &amp; Meats" ]; 
                
                [code_array addObject:@"PP.PA"];
                [name_array addObject:@"PPR"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Department Stores" ];
                
                [code_array addObject:@"VIV.PA"];
                [name_array addObject:@"VIVENDI"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Movies &amp; Entertainment" ];
                
                
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_GR"]  ) {
                
                
                
                [code_array addObject:@"BMW.DE"];
                [name_array addObject:@"BAYER MOTOREN WK"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Automobile Manufacturers" ];			
                
                
                
                [code_array addObject:@"BAYN.DE"];
                [name_array addObject:@"BAYER AG-REG"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Pharmaceuticals" ];   
                
                
                [code_array addObject:@"SIE.DE"];
                [name_array addObject:@"SIEMENS AG-REG"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Industrial Conglomerates" ]; 
                
                [code_array addObject:@"TKA.DE"];
                [name_array addObject:@"THYSSENKRUPP AG"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Steel" ];
                
                
                [code_array addObject:@"CBK.DE"];
                [name_array addObject:@"COMMERZBANK"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Banks" ];                
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_AX"]  ) {
                
                
                
                [code_array addObject:@"LYC.AX"];
                [name_array addObject:@"LYNAS CORP LTD"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Metals &amp; Mining" ];			
                
                
                
                [code_array addObject:@"SDL.AX"];
                [name_array addObject:@"SUNDANCE RESOURC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Steel" ];   
                
                
                [code_array addObject:@"TLS.AX"];
                [name_array addObject:@"TELSTRA CORP"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Integrated Telecommunication Services" ]; 
                
                [code_array addObject:@"GNS.AX"];
                [name_array addObject:@"GUNNS LTD"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Forest Products" ];
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_UK"]  ) {
                
                [code_array addObject:@"HSBA.L"];
                [name_array addObject:@"HSBC HLDGS PLC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Banks" ];			
                
                
                
                [code_array addObject:@"VOD.L"];
                [name_array addObject:@"VODAFONE GROUP"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Wireless Telecommunciation Service" ];                     
                
                
                [code_array addObject:@"RIO.L"];
                [name_array addObject:@"RIO TINTO PLC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Diversified Metals & Mining" ];                  
                
            }
            else if ([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_ETF"]) {
                /*
                [code_array addObject:@"QQQQ"];
                [name_array addObject:@"PowerShares QQQ"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"US Major Markets ETFs" ];			
                */
                
                
                
                [code_array addObject:@"ADRD"];
                [name_array addObject:@"BLDRS Developed Markets 100"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Broad International ETFs" ];
                
                
                [code_array addObject:@"GLD"];
                [name_array addObject:@"SPDR Gold Trust"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Commodity ETFs" ];			
                
                
                
                [code_array addObject:@"DXD"];
                [name_array addObject:@"ProShares UltraShort Dow 30"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Leveraged,Inverse" ];
                
                
                
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SI"]  ) {
                
                
                [code_array addObject:@"E5H.SI"];
                [name_array addObject:@"GoldenAgr"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Agriculture" ];			
                
                
                
                [code_array addObject:@"O32.SI"];
                [name_array addObject:@"Olam"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Commerce" ];   
                
                
                [code_array addObject:@"C31.SI"];
                [name_array addObject:@"Capitaland"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Properties" ]; 
                
                [code_array addObject:@"C38U.SI"];
                [name_array addObject:@"CapitaMall"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Properties" ];
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_US"]  ) {
                
                [code_array addObject:@"AAPL"];
                [name_array addObject:@"APPLE INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Computers & Peripherals" ];			
                
                
                
                [code_array addObject:@"INTU"];
                [name_array addObject:@"INTUIT INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Software" ];                     
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_INDIA"]  ) {
                
                [code_array addObject:@"SBIN.NS"];
                [name_array addObject:@"State Bank of India"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Money Center Bank" ];			
                
                
                
                [code_array addObject:@"RIL.BO"];
                [name_array addObject:@"Oil &amp;amp; Gas Refining &amp;amp; Marketing"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Software" ];                     
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_INDIA"]  ) {
                
                [code_array addObject:@"SBIN.NS"];
                [name_array addObject:@"State Bank of India"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Money Center Bank" ];			
                
                
                
                [code_array addObject:@"RIL.BO"];
                [name_array addObject:@"Oil &amp;amp; Gas Refining &amp;amp; Marketing"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Software" ];                     
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_NZ"]  ) {
                
                
                
                [code_array addObject:@"GMT.NZ"];
                [name_array addObject:@"Goodman Property Trust"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Undefine" ];			
                
                
                
                [code_array addObject:@"HLG.NZ"];
                [name_array addObject:@"Hallenstein Glasson Limited"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Apparel Stores" ];   
                
                
                [code_array addObject:@"VCT.NZ"];
                [name_array addObject:@"Vector Limited"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Electric Utilities" ]; 
                
                [code_array addObject:@"SAN.NZ"];
                [name_array addObject:@"Sanford Limited"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Farm Products" ];
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_NZ"]  ) {
                
                
                
                [code_array addObject:@"GMT.NZ"];
                [name_array addObject:@"Goodman Property Trust"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Undefine" ];			
                
                
                
                [code_array addObject:@"HLG.NZ"];
                [name_array addObject:@"Hallenstein Glasson Limited"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Apparel Stores" ];   
                
                
                [code_array addObject:@"VCT.NZ"];
                [name_array addObject:@"Vector Limited"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Electric Utilities" ]; 
                
                [code_array addObject:@"SAN.NZ"];
                [name_array addObject:@"Sanford Limited"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Farm Products" ];
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MI"]  ) {
                
                [code_array addObject:@"ATL.MI"];
                [name_array addObject:@"Atlantia"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Heavy Construction" ];			
                
                
                
                [code_array addObject:@"BUL.MI"];
                [name_array addObject:@"Bulgari"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Jewelry Stores" ];   
                
                
                [code_array addObject:@"DIA.MI"];
                [name_array addObject:@"Diasorin"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Medical Laboratories &amp;amp; Research" ];    
                
                
                [code_array addObject:@"EXO.MI"];
                [name_array addObject:@"EXOR S.p.A"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Conglomerates" ];
                
                
                
                
                
            }
			else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MI"]  ) {
                
                [code_array addObject:@"ATL.MI"];
                [name_array addObject:@"Atlantia"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Heavy Construction" ];			
                
                
                
                [code_array addObject:@"BUL.MI"];
                [name_array addObject:@"Bulgari"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Jewelry Stores" ];   
                
                
                [code_array addObject:@"DIA.MI"];
                [name_array addObject:@"Diasorin"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Medical Laboratories &amp;amp; Research" ];    
                
                
                [code_array addObject:@"EXO.MI"];
                [name_array addObject:@"EXOR S.p.A"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Conglomerates" ];
                
                
                
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_SA"]  ) {
                
                [code_array addObject:@"PETR4.SA"];
                [name_array addObject:@"PETROBRAS   -PN"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Integrated Oil &amp; Gas" ];			
                
                
                
                [code_array addObject:@"VALE5.SA"];
                [name_array addObject:@"VALE -PNA N1"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Steel" ];   
                
                
                [code_array addObject:@"OGXP3.SA"];
                [name_array addObject:@"OGX PETROLEO-ON NM"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Oil &amp; Gas Exploration &amp; Produc" ];    
                
                
                [code_array addObject:@"ITUB4.SA"];
                [name_array addObject:@"ITAUUNIBANCO-PN N1"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Banks" ];
                
                
                [code_array addObject:@"BBDC4.SA"];
                [name_array addObject:@"BCO Bradesco S.A."];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Banks" ];   
                
                
                [code_array addObject:@"GGBR4.SA"];
                [name_array addObject:@"GERDAU -PN N1"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Steel" ];    
                
                
                [code_array addObject:@"PETR3.SA"];
                [name_array addObject:@"PETROBRAS -ON"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Integrated Oil &amp; Gas_34.5" ];                
                
             
            
            
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_SA"]  ) {
                
                [code_array addObject:@"PETR4.SA"];
                [name_array addObject:@"PETROBRAS   -PN"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Integrated Oil &amp; Gas" ];			
                
                
                
                [code_array addObject:@"VALE5.SA"];
                [name_array addObject:@"VALE -PNA N1"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Steel" ];   
                
                
                [code_array addObject:@"OGXP3.SA"];
                [name_array addObject:@"OGX PETROLEO-ON NM"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Oil &amp; Gas Exploration &amp; Produc" ];    
                
                
                [code_array addObject:@"ITUB4.SA"];
                [name_array addObject:@"ITAUUNIBANCO-PN N1"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Banks" ];
                
                
                [code_array addObject:@"BBDC4.SA"];
                [name_array addObject:@"BCO Bradesco S.A."];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Banks" ];   
                
                
                [code_array addObject:@"GGBR4.SA"];
                [name_array addObject:@"GERDAU -PN N1"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Steel" ];    
                
                
                [code_array addObject:@"PETR3.SA"];
                [name_array addObject:@"PETROBRAS -ON"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Integrated Oil &amp; Gas_34.5" ];                
                
                
                
                
            }
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPad_MX"]  ) {
                
                [code_array addObject:@"AMXL.MX"];
                [name_array addObject:@"America Movil SAB de CV"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Wireless Telecommunication Ser" ];			
                
                
                
                [code_array addObject:@"GMEXICOB.MX"];
                [name_array addObject:@"Grupo Mexico, S.A.B De C.V"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Metals &amp; Mining" ];   
                
                
                [code_array addObject:@"ELEKTRA.MX"];
                [name_array addObject:@"Grupo Elektra, S.A. de C. V."];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Computer &amp; Electronics Retail" ];    
                
                
                [code_array addObject:@"WALMEXV.MX"];
                [name_array addObject:@"Wal-Mart De Mexico SAB de CV"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Hypermarkets &amp; Super Centers" ];
                
                
                [code_array addObject:@"ALFAA.MX"];
                [name_array addObject:@"Alfa, S.A.B. de C.V."];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Industrial Conglomerates" ];   
                
                
                [code_array addObject:@"GGBR4.SA"];
                [name_array addObject:@"GERDAU -PN N1"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Steel" ];    
                
                               
                
            }            
            else if([DisplayName isEqualToString:@"2D_BASIC_LF_iPhone_MX"]  ) {
                
                [code_array addObject:@"AMXL.MX"];
                [name_array addObject:@"America Movil SAB de CV"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Wireless Telecommunication Ser" ];			
                
                
                
                [code_array addObject:@"GMEXICOB.MX"];
                [name_array addObject:@"Grupo Mexico, S.A.B De C.V"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Metals &amp; Mining" ];   
                
                
                [code_array addObject:@"ELEKTRA.MX"];
                [name_array addObject:@"Grupo Elektra, S.A. de C. V."];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Computer &amp; Electronics Retail" ];    
                
                
                [code_array addObject:@"WALMEXV.MX"];
                [name_array addObject:@"Wal-Mart De Mexico SAB de CV"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Hypermarkets &amp; Super Centers" ];
                
                
                [code_array addObject:@"ALFAA.MX"];
                [name_array addObject:@"Alfa, S.A.B. de C.V."];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Industrial Conglomerates" ];   
                
                
                [code_array addObject:@"GGBR4.SA"];
                [name_array addObject:@"GERDAU -PN N1"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Steel" ];    
                
                
                
            }                        
            else if([DisplayName isEqualToString:@"2D_BASIC_MESA_iPhone_Global"]  ){
                
                
                [code_array addObject:@"AAPL"];
                [name_array addObject:@"APPLE INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Computers & Peripherals" ];			
                
                
                
                [code_array addObject:@"INTU"];
                [name_array addObject:@"INTUIT INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Software" ];
                
                
                
                [code_array addObject:@"0001.HK"];
                [name_array addObject:@"長江實業"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"地產" ];			
                
                
            }
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_AX"]  ) {
                
                
                
                [code_array addObject:@"LYC.AX"];
                [name_array addObject:@"LYNAS CORP LTD"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Metals &amp; Mining" ];			
                
                
                
                [code_array addObject:@"SDL.AX"];
                [name_array addObject:@"SUNDANCE RESOURC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Steel" ];   
                
                
                [code_array addObject:@"TLS.AX"];
                [name_array addObject:@"TELSTRA CORP"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Integrated Telecommunication Services" ]; 
                
                [code_array addObject:@"GNS.AX"];
                [name_array addObject:@"GUNNS LTD"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Forest Products" ];
                
                
            }
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_UK"]  ) {
                
                
                [code_array addObject:@"HSBA.L"];
                [name_array addObject:@"HSBC HLDGS PLC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Diversified Banks" ];			
                
                
                
                [code_array addObject:@"VOD.L"];
                [name_array addObject:@"VODAFONE GROUP"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Wireless Telecommunciation Service" ];                     
                
                
                [code_array addObject:@"RIO.L"];
                [name_array addObject:@"RIO TINTO PLC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Diversified Metals & Mining" ];   
                
                
            }
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_US"]  ) {
                [code_array addObject:@"AAPL"];
                [name_array addObject:@"APPLE INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Computers & Peripherals" ];			
                
                
                
                [code_array addObject:@"INTU"];
                [name_array addObject:@"INTUIT INC"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Software" ];                      
                
                
            }
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_HK"]  ) {
                
                
                [code_array addObject:@"0001.HK"];
                [name_array addObject:@"長江實業"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"地產" ];			
                
                
                
                [code_array addObject:@"0700.HK"];
                [name_array addObject:@"騰訊"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"資訊科技業" ];   
                
                
                [code_array addObject:@"0013.HK"];
                [name_array addObject:@"和記黃埔"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"綜合企業" ];    
                
                
            }
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_CH"]  ) {
                
                
                [code_array addObject:@"600111.SS"];
                [name_array addObject:@"包钢稀土"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"制造业" ];			
                
                
                
                [code_array addObject:@"600585.SS"];
                [name_array addObject:@"海螺水泥"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"制造业" ];   
                
                
                [code_array addObject:@"600058.SS"];
                [name_array addObject:@"五矿发展"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"批发和零售贸易" ];                   
                
            }
            else if([DisplayName isEqualToString:@"2D_Basic_MESA_Universal_INDIA"]  ) {
                
                [code_array addObject:@"SBIN.NS"];
                [name_array addObject:@"State Bank of India"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject: @"Money Center Bank" ];			
                
                
                
                [code_array addObject:@"RIL.BO"];
                [name_array addObject:@"Oil &amp;amp; Gas Refining &amp;amp; Marketing"];
                [class_array addObject:NSLocalizedString(@"Sample1",@"Sample1")];
                [id_class_array addObject :@"Software" ];                     
                
                
            }
            
            
            
            WillSaveFirstWatchlist=YES;            
            
            /*
			//儲存自選股群組
			[self SaveGroupName];
			
			//儲存自選股明細
			NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
			NSString *dir = [paths objectAtIndex:0];
			NSString *filePathw;
			filePathw = [[NSString alloc] initWithString:[dir stringByAppendingPathComponent:[NSString stringWithFormat: @"WatchList_%@.cplist",NSLocalizedString(@"Sample1",@"Sample1")]]];
			NSMutableArray *awr;
			awr=[[NSMutableArray alloc] init];
			for (int i=0; i<[code_array count]; i++) {
				NSString *wr;
				wr=[NSString stringWithFormat:@"%@_%@_%@_34.5_56000",[code_array objectAtIndex:i],[name_array objectAtIndex:i], [id_class_array objectAtIndex:i]];
				[awr addObject:wr];
			}
			
             [awr writeToFile:filePathw atomically:NO];					
			 [filePathw release];
             [awr release];
			 */
		}  
        else {
			//已經有檔案 
			 watchc= [[NSMutableArray alloc] initWithContentsOfFile:filePathw];
            [filePathw release];
			 for (NSString *s in watchc) {
				 //自選股分類 
				 [classd addObject:s];
				 NSString *filePathwc;
				 filePathwc = [[NSString alloc] initWithString:[dir stringByAppendingPathComponent:[NSString stringWithFormat:@"WatchList_%@.cplist",s]]]	;	
				 NSMutableArray *watchcaa;
				 watchcaa= [[NSMutableArray alloc] initWithContentsOfFile:filePathwc];	
                 [filePathwc release];
				 for (NSString *sc in watchcaa) {
					 
					 NSArray *copm=[sc componentsSeparatedByString:@"_"];
					 //0:代碼 1:名稱 2:買入時間 3:買入成本 4:買入股數
					 [code_array addObject:[copm objectAtIndex:0]];
					 [name_array addObject:[copm objectAtIndex:1]];
					 [class_array addObject:s];
					 [id_class_array addObject:[copm objectAtIndex:2]];
					  
					 
					 
				 }
                 [watchcaa release];
				 
			 }
            [watchc release];
        }
	 		
		/*
        NSMutableArray *sectionArray_pre;
        NSMutableArray *code_sarray_pre;
        NSMutableArray *name_sarray_pre;
        NSMutableArray *class_sarray_pre;
        NSMutableArray *id_class_sarray_pre;
          
        NSAutoreleasePool * pool_2 = [[NSAutoreleasePool alloc] init];        
        
        sectionArray_pre=sectionArray;
        code_sarray_pre= code_sarray;
        name_sarray_pre= name_sarray;
        class_sarray_pre=class_sarray;
        id_class_sarray_pre=  id_class_sarray;      
        
        [sectionArray_pre autorelease];
        [code_sarray_pre autorelease];
        [name_sarray_pre autorelease];
        [class_sarray_pre autorelease];
        [id_class_sarray_pre autorelease];
        
        
        */
        sectionArray = [[NSMutableArray alloc] init];
		code_sarray=	[[NSMutableArray alloc] init];
		name_sarray=	[[NSMutableArray alloc] init];
        class_sarray=[[NSMutableArray alloc] init];
		id_class_sarray=[[NSMutableArray alloc] init];		
		 
		// [pool_2 release];
        
        
        NSMutableArray *sectionArray_sub;
        NSMutableArray *code_sarray_sub;
        NSMutableArray *name_sarray_sub;
        NSMutableArray *class_sarray_sub;
        NSMutableArray *id_class_sarray_sub;        
		/*
         
         
         
         
         */
		
		for (int i = 0; i < [classd count]; i++){ 
            sectionArray_sub = [[NSMutableArray alloc] init];
            [sectionArray addObject:sectionArray_sub];
            [sectionArray_sub release];
            
        }
		
		for (int i = 0; i < [classd count]; i++){
            code_sarray_sub=	[[NSMutableArray alloc] init];
            [code_sarray addObject:code_sarray_sub];
            [code_sarray_sub release];
            
        }
		for (int i = 0; i < [classd count]; i++) {
            name_sarray_sub=	[[NSMutableArray alloc] init];
            [name_sarray addObject: name_sarray_sub];
            [name_sarray_sub release];
            
        }
        
		for (int i = 0; i < [classd count]; i++) {
            class_sarray_sub=[[NSMutableArray alloc] init];      
            [class_sarray addObject: class_sarray_sub];
            
            [ class_sarray_sub release];            
        }
		for (int i = 0; i < [classd count]; i++){
            id_class_sarray_sub=[[NSMutableArray alloc] init];
            [id_class_sarray addObject:id_class_sarray_sub];
            [id_class_sarray_sub release];
            
        }

		for (int i = 0; i < [code_array count]; i++)
		
        
        
        {
			//全部市場 
			[[sectionArray objectAtIndex:0] addObject:[code_array objectAtIndex:i]];
		              
            [[code_sarray objectAtIndex:0] addObject:[code_array objectAtIndex:i]];		
			[[name_sarray objectAtIndex:0] addObject:[name_array objectAtIndex:i]];	
			 
			[[class_sarray objectAtIndex:0] addObject:[class_array objectAtIndex:i]];		
			[[id_class_sarray objectAtIndex:0] addObject:[id_class_array objectAtIndex:i]];	
		  
			
			//產業別
			[[sectionArray objectAtIndex:[classd indexOfObject:[class_array objectAtIndex:i]]]addObject:[code_array objectAtIndex:i]];
			[[code_sarray objectAtIndex:[classd indexOfObject:[class_array objectAtIndex:i]]]addObject:[code_array objectAtIndex:i]];
			[[name_sarray objectAtIndex:[classd indexOfObject:[class_array objectAtIndex:i]]]addObject:[name_array objectAtIndex:i]];
			 
			[[class_sarray objectAtIndex:[classd indexOfObject:[class_array objectAtIndex:i]]]addObject:[class_array objectAtIndex:i]];
			[[id_class_sarray objectAtIndex:[classd indexOfObject:[class_array objectAtIndex:i]]]addObject:[id_class_array objectAtIndex:i]];
			 
			
		 
			
		}
		
		
		NSLog(@"WATCHLIST_end");		
	}
	else {
        //標記:記憶體釋放技巧 1.alloc 之前的動作
        /*
         a.宣告暫時紀錄之前的指標
         NSMutableArray *code_pre;
         b.將要消除的指標位置給另外一個紀錄指標
         code_pre=code_array;
         c.產生新記憶體
         code_array=	[[NSMutableArray alloc] init];
         d.消除前一記憶體  
         [code_pre release];
         */
        
        
           //從資料庫取出資料
            const char *sql = NULL;	
            NSString *tsql;
            
            tsql=@"SELECT id,Symbol,Lname,Ename,Class FROM ";
            tsql=[tsql stringByAppendingString:NSLocalizedString(self.title,self.title)];
            sql=[tsql UTF8String];		
	 		
               
            
            code_array=	[[NSMutableArray alloc] init];
            name_array=	[[NSMutableArray alloc] init];
            class_array=[[NSMutableArray alloc] init];
            id_class_array=[[NSMutableArray alloc] init];		
            classd=[[NSMutableArray alloc] init];        
         
                      
            
            //抽取出產業分類
            
            //[classd addObject:NSLocalizedString(@"全部市場",@"全部市場")];
            
            /*請注意第ㄧ次開啓執行時,是將在ＡＰＰ檔裡的資料庫檔案複製到iphone Documents裡 所以只要資料庫要修改或欄位新增
             務必要將整個在iphone檔案全部刪除
             透過DBHelper實體方便建立資料庫使用實體 所以如果要使用資料庫要把 DBHelper.h DBHelper.m 引用進入 
             */
            //啓動資料庫檔案 輸入檔名與副執行檔名稱與全名
            NSString *ver;
            ver=[[[NSBundle mainBundle] infoDictionary] objectForKey:@"CFBundleVersion"];
            ver=[ver stringByReplacingOccurrencesOfString:@"." withString:@"_"];
            NSString *filename;
            filename=@"data_";
            filename=[filename stringByAppendingString:ver];
            NSString *filenamexx;
            filenamexx=@"sqlite3";
            NSString *fullfilename;
            fullfilename=[filename stringByAppendingString:@"."];
            fullfilename=[fullfilename stringByAppendingString:filenamexx];
            DBHelper *helper =[DBHelper newInstance:filename andEXT:filenamexx andfullname:fullfilename];
            
            
            sqlite3 *database = [helper openDatabase]; 
            sqlite3_stmt *stm;
            
            if(sqlite3_prepare_v2(database, sql, strlen(sql), &stm, NULL)== SQLITE_OK) {
                
                while(sqlite3_step(stm) ==SQLITE_ROW)
                {
                    //int row=sqlite3_column_int(stm, 0);
                    //NSString *ii=[[NSString alloc] initWithFormat:@"%d" ,row];
                    //sqlite3_column_text
                    //sqlite3_column_int
                    //sqlite3_column_double
                    //1:代號
                    
                    char *field1=(char *)sqlite3_column_text(stm, 1);
                   
                    //標記:記憶體釋放技巧 2. 要盡量使用 [[NSString alloc] .... 避免使用[NSString
                    
                    NSString *ss1;
                    ss1=[[NSString alloc] initWithUTF8String: field1];
                                   
                    
                    [code_array addObject:ss1];		
                    [ss1 release];
                    //標記:記憶體釋放技巧 3. addObject 之後記住要 release                    
                    
                    //2:名稱
                    char *field2=(char *)sqlite3_column_text(stm, 2);
                    NSString *ss2;
                    ss2=[[NSString alloc] initWithUTF8String:  field2];
                    [name_array addObject:ss2];			
                    [ss2 release];
                    
                    
                    char *field5=(char *)sqlite3_column_text(stm, 4);
                    NSString *ss5;
                    ss5=[[NSString alloc] initWithUTF8String: field5];
                    
                    [class_array addObject:ss5]	;			
                    [id_class_array addObject:ss5]	;					
                    
                    if([classd indexOfObject:ss5]==NSNotFound)
                    {
                        [classd addObject:ss5];
                        
                    }
                    [ss5 release]; 
                    
                }
                //code_array=tcode_array;
            }
            //結束查詢作業
            sqlite3_finalize(stm);
            
           
          
         
            //標頭分類排序
            //標記:記憶體釋放技巧 5.排序陣列釋放技巧        
          
           //標記: sortUsingFunction:是一種NSMutableArray方法，重新命令的數組對象，不返回值       
           [classd sortUsingFunction:comparator_TableTitle  context:nil];
           
        
        //因為sortclassd 是autorelease 所以要用retain保留       
            
            
            NSMutableArray *code_sarray_pre;
            NSMutableArray *name_sarray_pre; 
            NSMutableArray *class_sarray_pre;
            NSMutableArray *id_class_sarray_pre;        
            NSMutableArray *sectionArray_pre; 
        
            code_sarray_pre=  code_sarray;  
            name_sarray_pre=name_sarray;
            class_sarray_pre=  class_sarray;  
            id_class_sarray_pre=id_class_sarray;        
            sectionArray_pre=sectionArray;        
        
            sectionArray = [[NSMutableArray alloc] init];
            code_sarray=	[[NSMutableArray alloc] init];
            name_sarray=	[[NSMutableArray alloc] init];
            class_sarray=[[NSMutableArray alloc] init];
            id_class_sarray=[[NSMutableArray alloc] init];		
            
            if (code_sarray_pre!=nil) {
                //[code_sarray_pre release];
            }
            if ( name_sarray_pre!=nil) {
               // [ name_sarray_pre release];
            }
            if ( class_sarray_pre!=nil) {
               // [ class_sarray_pre release];
             }
            if ( id_class_sarray_pre!=nil) {
               // [id_class_sarray_pre release];
            }
            if (sectionArray_pre!=nil) {
               // [sectionArray_pre release];
            }            
            NSMutableArray *sectionArray_sub;
            NSMutableArray *code_sarray_sub;
            NSMutableArray *name_sarray_sub;
            NSMutableArray *class_sarray_sub;
            NSMutableArray *id_class_sarray_sub;        
             
            
            for (int i = 0; i < [classd count]; i++){ 
                sectionArray_sub = [[NSMutableArray alloc] init];
                [sectionArray addObject:sectionArray_sub];
                [sectionArray_sub release];
                
            }
            
            for (int i = 0; i < [classd count]; i++){
                code_sarray_sub=	[[NSMutableArray alloc] init];
                [code_sarray addObject:code_sarray_sub];
                [code_sarray_sub release];
                
            }
            for (int i = 0; i < [classd count]; i++) {
                name_sarray_sub=	[[NSMutableArray alloc] init];
                [name_sarray addObject: name_sarray_sub];
                [name_sarray_sub release];
                
            }
            
            for (int i = 0; i < [classd count]; i++) {
                class_sarray_sub=[[NSMutableArray alloc] init];      
                [class_sarray addObject: class_sarray_sub];
                
                [ class_sarray_sub release];            
            }
            for (int i = 0; i < [classd count]; i++){
                id_class_sarray_sub=[[NSMutableArray alloc] init];
                [id_class_sarray addObject:id_class_sarray_sub];
                [id_class_sarray_sub release];
                
            }
            
            
            
            
            
            for (int i = 0; i < [code_array count]; i++)
            {
                //產業別
                [[sectionArray objectAtIndex:[classd indexOfObject:[class_array objectAtIndex:i]]]addObject:[code_array objectAtIndex:i]];
                
                [[code_sarray objectAtIndex:[classd indexOfObject:[class_array objectAtIndex:i]]]addObject:[code_array objectAtIndex:i]];
                [[name_sarray objectAtIndex:[classd indexOfObject:[class_array objectAtIndex:i]]]addObject:[name_array objectAtIndex:i]];
                
                [[class_sarray objectAtIndex:[classd indexOfObject:[class_array objectAtIndex:i]]]addObject:[class_array objectAtIndex:i]];
                
                [[id_class_sarray objectAtIndex:[classd indexOfObject:[class_array objectAtIndex:i]]]addObject:[id_class_array objectAtIndex:i]];
                
                
            }
            
            //消除取出資料記憶體
             //[code_array release];
             //[name_array release];
            // [class_array release];
            //[id_class_array release];           
            
        //[helper closeDatabase];
            
            
        }
        
                       
	 
	
}

-(void)didReceiveMemoryWarning {
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}
-(void)viewDidUnload {
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}
-(void)dealloc {
	
	//[myTable release];
	//myTable=nil;
	//[navdelegete release];
	//navdelegete=nil;
	
    [super dealloc];
}


#pragma mark -
#pragma mark 標頭分類排序方法
NSInteger comparator_TableTitle(NSString *d1, NSString *d2, void *context )
{
	return [d1 compare:d2];
}


@end